﻿Imports Microsoft.VisualBasic.CompilerServices
Imports System

Namespace Stickam_Client
    Public Class UserlistClass
        ' Methods
        Public Sub New(ByVal ParentForm As Form1)
            Me.FormParent = ParentForm
        End Sub

        Public Sub add(ByVal newUserID As String, ByVal newID As String, ByVal newUserName As String, ByVal newScreenName As String, ByVal newIsVideo As Boolean, ByVal newIsModerator As Boolean, ByVal newIsOwner As Boolean, ByVal newUserType As String, ByVal newSessionType As String, ByVal newLangID As String, ByVal newComponentBit As String)
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_userID, newUserID)
            If (index = -1) Then
                Me.Array_componentBit = DirectCast(Utils.CopyArray(DirectCast(Me.Array_componentBit, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_font = DirectCast(Utils.CopyArray(DirectCast(Me.Array_font, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_fontBold = DirectCast(Utils.CopyArray(DirectCast(Me.Array_fontBold, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_fontColor = DirectCast(Utils.CopyArray(DirectCast(Me.Array_fontColor, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_fontItalics = DirectCast(Utils.CopyArray(DirectCast(Me.Array_fontItalics, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_fontSize = DirectCast(Utils.CopyArray(DirectCast(Me.Array_fontSize, Array), New Integer((Me.total + 1)  - 1) {}), Integer())
                Me.Array_fontUnderline = DirectCast(Utils.CopyArray(DirectCast(Me.Array_fontUnderline, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_id = DirectCast(Utils.CopyArray(DirectCast(Me.Array_id, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_isIgnored = DirectCast(Utils.CopyArray(DirectCast(Me.Array_isIgnored, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_isModerator = DirectCast(Utils.CopyArray(DirectCast(Me.Array_isModerator, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_isOwner = DirectCast(Utils.CopyArray(DirectCast(Me.Array_isOwner, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_isVideo = DirectCast(Utils.CopyArray(DirectCast(Me.Array_isVideo, Array), New Boolean((Me.total + 1)  - 1) {}), Boolean())
                Me.Array_langID = DirectCast(Utils.CopyArray(DirectCast(Me.Array_langID, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_screenName = DirectCast(Utils.CopyArray(DirectCast(Me.Array_screenName, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_sessionType = DirectCast(Utils.CopyArray(DirectCast(Me.Array_sessionType, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_userID = DirectCast(Utils.CopyArray(DirectCast(Me.Array_userID, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_userName = DirectCast(Utils.CopyArray(DirectCast(Me.Array_userName, Array), New String((Me.total + 1)  - 1) {}), String())
                Me.Array_userType = DirectCast(Utils.CopyArray(DirectCast(Me.Array_userType, Array), New String((Me.total + 1)  - 1) {}), String())
                index = Me.total
                Me.total += 1
                Me.Array_font(index) = "Arial"
                Me.Array_fontBold(index) = False
                Me.Array_fontColor(index) = "000000"
                Me.Array_fontItalics(index) = False
                Me.Array_fontSize(index) = 12
                Me.Array_fontUnderline(index) = False
                Me.Array_isIgnored(index) = False
            Else
                Me.RemoveUsername(Me.Array_screenName(index))
                Me.FormParent.UserlistCtl.Nodes.RemoveByKey(newUserID)
            End If
            Me.Array_componentBit(index) = newComponentBit
            Me.Array_id(index) = newID
            Me.Array_isModerator(index) = newIsModerator
            Me.Array_isOwner(index) = newIsOwner
            Me.Array_isVideo(index) = newIsVideo
            Me.Array_langID(index) = newLangID
            Me.Array_screenName(index) = newScreenName
            Me.Array_sessionType(index) = newSessionType
            Me.Array_userID(index) = newUserID
            Me.Array_userName(index) = newUserName
            Me.Array_userType(index) = newUserType
            Dim imageKey As String = "user_reg"
            If newIsVideo Then
                imageKey = "user_cam"
            End If
            If newIsModerator Then
                imageKey = "user_mod"
            End If
            If newIsOwner Then
                imageKey = "user_host"
            End If
            If (newUserType = "200") Then
                imageKey = "user_glb"
            End If
            Me.Usernames = DirectCast(Utils.CopyArray(DirectCast(Me.Usernames, Array), New String((Me.Usernames.Length + 1)  - 1) {}), String())
            Me.Usernames((Me.Usernames.Length - 1)) = newScreenName
            Array.Sort(Of String)(Me.Usernames)
            Dim num2 As Integer = (Array.IndexOf(Of String)(Me.Usernames, newScreenName) - 1)
            Me.FormParent.UserlistCtl.Nodes.Insert(num2, newUserID, newScreenName, imageKey, imageKey)
        End Sub

        Public Sub clear()
            Me.total = 0
            Me.Array_componentBit = New String(1  - 1) {}
            Me.Array_font = New String(1  - 1) {}
            Me.Array_fontBold = New Boolean(1  - 1) {}
            Me.Array_fontColor = New String(1  - 1) {}
            Me.Array_fontItalics = New Boolean(1  - 1) {}
            Me.Array_fontSize = New Integer(1  - 1) {}
            Me.Array_fontUnderline = New Boolean(1  - 1) {}
            Me.Array_id = New String(1  - 1) {}
            Me.Array_isIgnored = New Boolean(1  - 1) {}
            Me.Array_isModerator = New Boolean(1  - 1) {}
            Me.Array_isOwner = New Boolean(1  - 1) {}
            Me.Array_isVideo = New Boolean(1  - 1) {}
            Me.Array_langID = New String(1  - 1) {}
            Me.Array_screenName = New String(1  - 1) {}
            Me.Array_sessionType = New String(1  - 1) {}
            Me.Array_userID = New String(1  - 1) {}
            Me.Array_userName = New String(1  - 1) {}
            Me.Array_userType = New String(1  - 1) {}
            Me.Usernames = New String(1  - 1) {}
            Me.FormParent.UserlistCtl.Nodes.Clear
        End Sub

        Public Function getParam(ByVal byUserID As String, ByVal paramType As Integer) As Object
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_userID, byUserID)
            If (index <> -1) Then
                Return Me.getParamByIndex(index, paramType)
            End If
            Return ""
        End Function

        Public Function getParamByIndex(ByVal Index As Integer, ByVal paramType As Integer) As Object
            Dim num As Integer = paramType
            If (num = Me.componentBit) Then
                Return Me.Array_componentBit(Index)
            End If
            If (num = Me.font) Then
                Return Me.Array_font(Index)
            End If
            If (num = Me.fontBold) Then
                Return Me.Array_fontBold(Index)
            End If
            If (num = Me.fontColor) Then
                Return Me.Array_fontColor(Index)
            End If
            If (num = Me.fontItalics) Then
                Return Me.Array_fontItalics(Index)
            End If
            If (num = Me.fontSize) Then
                Return Me.Array_fontSize(Index)
            End If
            If (num = Me.fontUnderline) Then
                Return Me.Array_fontUnderline(Index)
            End If
            If (num = Me.id) Then
                Return Me.Array_id(Index)
            End If
            If (num = -(Me.isIgnored > False)) Then
                Return Me.Array_isIgnored(Index)
            End If
            If (num = Me.isModerator) Then
                Return Me.Array_isModerator(Index)
            End If
            If (num = Me.isOwner) Then
                Return Me.Array_isOwner(Index)
            End If
            If (num = Me.isVideo) Then
                Return Me.Array_isVideo(Index)
            End If
            If (num = Me.langID) Then
                Return Me.Array_langID(Index)
            End If
            If (num = Me.screenName) Then
                Return Me.Array_screenName(Index)
            End If
            If (num = Me.sessionType) Then
                Return Me.Array_sessionType(Index)
            End If
            If (num = Me.userID) Then
                Return Me.Array_userID(Index)
            End If
            If (num = Me.userName) Then
                Return Me.Array_userName(Index)
            End If
            If (num = Me.userType) Then
                Return Me.Array_userType(Index)
            End If
            Return ""
        End Function

        Public Function getParamByScreenName(ByVal byScreenName As String, ByVal paramType As Integer) As Object
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_screenName, byScreenName)
            If (index <> -1) Then
                Return Me.getParamByIndex(index, paramType)
            End If
            Return ""
        End Function

        Public Function getParamByUserName(ByVal byUserName As String, ByVal paramType As Integer) As Object
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_userName, byUserName)
            If (index <> -1) Then
                Return Me.getParamByIndex(index, paramType)
            End If
            Return ""
        End Function

        Public Sub remove(ByVal oldUserID As String)
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_userID, oldUserID)
            If (index <> -1) Then
                Me.RemoveUsername(Me.Array_screenName(index))
                Array.Clear(Me.Array_componentBit, index, 1)
                Array.Clear(Me.Array_font, index, 1)
                Array.Clear(Me.Array_fontBold, index, 1)
                Array.Clear(Me.Array_fontColor, index, 1)
                Array.Clear(Me.Array_fontItalics, index, 1)
                Array.Clear(Me.Array_fontSize, index, 1)
                Array.Clear(Me.Array_fontUnderline, index, 1)
                Array.Clear(Me.Array_id, index, 1)
                Array.Clear(Me.Array_isIgnored, index, 1)
                Array.Clear(Me.Array_isModerator, index, 1)
                Array.Clear(Me.Array_isOwner, index, 1)
                Array.Clear(Me.Array_isVideo, index, 1)
                Array.Clear(Me.Array_langID, index, 1)
                Array.Clear(Me.Array_screenName, index, 1)
                Array.Clear(Me.Array_sessionType, index, 1)
                Array.Clear(Me.Array_userID, index, 1)
                Array.Clear(Me.Array_userName, index, 1)
                Array.Clear(Me.Array_userType, index, 1)
            End If
            Me.FormParent.UserlistCtl.Nodes.RemoveByKey(oldUserID)
        End Sub

        Private Sub RemoveUsername(ByVal Username As String)
            Dim index As Integer = Array.IndexOf(Of String)(Me.Usernames, Username)
            If (Me.Usernames.Length > 2) Then
                Me.Usernames(index) = Me.Usernames((Me.Usernames.Length - 1))
            End If
            Me.Usernames = DirectCast(Utils.CopyArray(DirectCast(Me.Usernames, Array), New String(((Me.Usernames.Length - 2) + 1)  - 1) {}), String())
        End Sub

        Public Sub setIgnore(ByVal curUserID As String, ByVal newIsIgnored As Boolean)
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_userID, curUserID)
            If (index <> -1) Then
                Me.Array_isIgnored(index) = newIsIgnored
            End If
        End Sub

        Public Sub updateFont(ByVal curUserID As String, ByVal newFont As String, ByVal newFontColor As String, ByVal newFontSize As Integer, ByVal newIsBold As Boolean, ByVal newIsItalics As Boolean, ByVal newIsUnderline As Boolean)
            Dim index As Integer = Array.IndexOf(Of String)(Me.Array_userID, curUserID)
            If (index <> -1) Then
                Me.Array_font(index) = newFont
                Me.Array_fontBold(index) = newIsBold
                Me.Array_fontColor(index) = newFontColor
                Me.Array_fontItalics(index) = newIsItalics
                Me.Array_fontSize(index) = newFontSize
                Me.Array_fontUnderline(index) = newIsUnderline
            End If
        End Sub


        ' Fields
        Private Array_componentBit As String() = New String(1  - 1) {}
        Private Array_font As String() = New String(1  - 1) {}
        Private Array_fontBold As Boolean() = New Boolean(1  - 1) {}
        Private Array_fontColor As String() = New String(1  - 1) {}
        Private Array_fontItalics As Boolean() = New Boolean(1  - 1) {}
        Private Array_fontSize As Integer() = New Integer(1  - 1) {}
        Private Array_fontUnderline As Boolean() = New Boolean(1  - 1) {}
        Private Array_id As String() = New String(1  - 1) {}
        Private Array_isIgnored As Boolean() = New Boolean(1  - 1) {}
        Private Array_isModerator As Boolean() = New Boolean(1  - 1) {}
        Private Array_isOwner As Boolean() = New Boolean(1  - 1) {}
        Private Array_isVideo As Boolean() = New Boolean(1  - 1) {}
        Private Array_langID As String() = New String(1  - 1) {}
        Private Array_screenName As String() = New String(1  - 1) {}
        Private Array_sessionType As String() = New String(1  - 1) {}
        Private Array_userID As String() = New String(1  - 1) {}
        Private Array_userName As String() = New String(1  - 1) {}
        Private Array_userType As String() = New String(1  - 1) {}
        Public componentBit As Integer = 10
        Public font As Integer = 11
        Public fontBold As Integer = 14
        Public fontColor As Integer = 12
        Public fontItalics As Integer = 15
        Public fontSize As Integer = 13
        Public fontUnderline As Integer = &H10
        Private FormParent As Form1
        Public id As Integer = 1
        Public isIgnored As Boolean = True
        Public isModerator As Integer = 5
        Public isOwner As Integer = 6
        Public isVideo As Integer = 4
        Public langID As Integer = 9
        Public screenName As Integer = 3
        Public sessionType As Integer = 8
        Public total As Integer = 0
        Public userID As Integer = 0
        Public userName As Integer = 2
        Public Usernames As String() = New String(1  - 1) {}
        Public userType As Integer = 7
    End Class
End Namespace

